package org.gap.dao;

import java.util.Arrays;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.Set;

import javax.persistence.EntityManager;
import javax.persistence.NoResultException;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

import org.gap.domain.RendezVous;

import org.skyway.spring.util.dao.AbstractJpaDao;

import org.springframework.dao.DataAccessException;

import org.springframework.stereotype.Repository;

import org.springframework.transaction.annotation.Transactional;

/**
 * DAO to manage RendezVous entities.
 * 
 */
@Repository("RendezVousDAO")
@Transactional
public class RendezVousDAOImpl extends AbstractJpaDao<RendezVous> implements
		RendezVousDAO {

	/**
	 * Set of entity classes managed by this DAO.  Typically a DAO manages a single entity.
	 *
	 */
	private final static Set<Class<?>> dataTypes = new HashSet<Class<?>>(Arrays.asList(new Class<?>[] { RendezVous.class }));

	/**
	 * EntityManager injected by Spring for persistence unit 
	 *
	 */
	@PersistenceContext(unitName = "")
	private EntityManager entityManager;

	/**
	 * Instantiates a new RendezVousDAOImpl
	 *
	 */
	public RendezVousDAOImpl() {
		super();
	}

	/**
	 * Get the entity manager that manages persistence unit 
	 *
	 */
	public EntityManager getEntityManager() {
		return entityManager;
	}

	/**
	 * Returns the set of entity classes managed by this DAO.
	 *
	 */
	public Set<Class<?>> getTypes() {
		return dataTypes;
	}

	/**
	 * JPQL Query - findRendezVousByRdvDate
	 *
	 */
	@Transactional
	public Set<RendezVous> findRendezVousByRdvDate(java.util.Calendar rdvDate) throws DataAccessException {

		return findRendezVousByRdvDate(rdvDate, -1, -1);
	}

	/**
	 * JPQL Query - findRendezVousByRdvDate
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<RendezVous> findRendezVousByRdvDate(java.util.Calendar rdvDate, int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findRendezVousByRdvDate", startResult, maxRows, rdvDate);
		return new LinkedHashSet<RendezVous>(query.getResultList());
	}

	/**
	 * JPQL Query - findRendezVousByRdvRendezVous
	 *
	 */
	@Transactional
	public RendezVous findRendezVousByRdvRendezVous(Integer rdvRendezVous) throws DataAccessException {

		return findRendezVousByRdvRendezVous(rdvRendezVous, -1, -1);
	}

	/**
	 * JPQL Query - findRendezVousByRdvRendezVous
	 *
	 */

	@Transactional
	public RendezVous findRendezVousByRdvRendezVous(Integer rdvRendezVous, int startResult, int maxRows) throws DataAccessException {
		try {
			return executeQueryByNameSingleResult("findRendezVousByRdvRendezVous", rdvRendezVous);
		} catch (NoResultException nre) {
			return null;
		}
	}

	/**
	 * JPQL Query - findRendezVousByPrimaryKey
	 *
	 */
	@Transactional
	public RendezVous findRendezVousByPrimaryKey(Integer rdvRendezVous) throws DataAccessException {

		return findRendezVousByPrimaryKey(rdvRendezVous, -1, -1);
	}

	/**
	 * JPQL Query - findRendezVousByPrimaryKey
	 *
	 */

	@Transactional
	public RendezVous findRendezVousByPrimaryKey(Integer rdvRendezVous, int startResult, int maxRows) throws DataAccessException {
		try {
			return executeQueryByNameSingleResult("findRendezVousByPrimaryKey", rdvRendezVous);
		} catch (NoResultException nre) {
			return null;
		}
	}

	/**
	 * JPQL Query - findRendezVousByRdvSpecialite
	 *
	 */
	@Transactional
	public Set<RendezVous> findRendezVousByRdvSpecialite(String rdvSpecialite) throws DataAccessException {

		return findRendezVousByRdvSpecialite(rdvSpecialite, -1, -1);
	}

	/**
	 * JPQL Query - findRendezVousByRdvSpecialite
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<RendezVous> findRendezVousByRdvSpecialite(String rdvSpecialite, int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findRendezVousByRdvSpecialite", startResult, maxRows, rdvSpecialite);
		return new LinkedHashSet<RendezVous>(query.getResultList());
	}

	/**
	 * JPQL Query - findRendezVousByRdvAdmission
	 *
	 */
	@Transactional
	public Set<RendezVous> findRendezVousByRdvAdmission(Integer rdvAdmission) throws DataAccessException {

		return findRendezVousByRdvAdmission(rdvAdmission, -1, -1);
	}

	/**
	 * JPQL Query - findRendezVousByRdvAdmission
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<RendezVous> findRendezVousByRdvAdmission(Integer rdvAdmission, int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findRendezVousByRdvAdmission", startResult, maxRows, rdvAdmission);
		return new LinkedHashSet<RendezVous>(query.getResultList());
	}

	/**
	 * JPQL Query - findRendezVousByRdvDateAfter
	 *
	 */
	@Transactional
	public Set<RendezVous> findRendezVousByRdvDateAfter(java.util.Calendar rdvDate) throws DataAccessException {

		return findRendezVousByRdvDateAfter(rdvDate, -1, -1);
	}

	/**
	 * JPQL Query - findRendezVousByRdvDateAfter
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<RendezVous> findRendezVousByRdvDateAfter(java.util.Calendar rdvDate, int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findRendezVousByRdvDateAfter", startResult, maxRows, rdvDate);
		return new LinkedHashSet<RendezVous>(query.getResultList());
	}

	/**
	 * JPQL Query - findRendezVousByRdvDateBefore
	 *
	 */
	@Transactional
	public Set<RendezVous> findRendezVousByRdvDateBefore(java.util.Calendar rdvDate) throws DataAccessException {

		return findRendezVousByRdvDateBefore(rdvDate, -1, -1);
	}

	/**
	 * JPQL Query - findRendezVousByRdvDateBefore
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<RendezVous> findRendezVousByRdvDateBefore(java.util.Calendar rdvDate, int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findRendezVousByRdvDateBefore", startResult, maxRows, rdvDate);
		return new LinkedHashSet<RendezVous>(query.getResultList());
	}

	/**
	 * JPQL Query - findAllRendezVouss
	 *
	 */
	@Transactional
	public Set<RendezVous> findAllRendezVouss() throws DataAccessException {

		return findAllRendezVouss(-1, -1);
	}

	/**
	 * JPQL Query - findAllRendezVouss
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<RendezVous> findAllRendezVouss(int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findAllRendezVouss", startResult, maxRows);
		return new LinkedHashSet<RendezVous>(query.getResultList());
	}

	/**
	 * JPQL Query - findRendezVousByRdvTiers
	 *
	 */
	@Transactional
	public Set<RendezVous> findRendezVousByRdvTiers(Integer rdvTiers) throws DataAccessException {

		return findRendezVousByRdvTiers(rdvTiers, -1, -1);
	}

	/**
	 * JPQL Query - findRendezVousByRdvTiers
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<RendezVous> findRendezVousByRdvTiers(Integer rdvTiers, int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findRendezVousByRdvTiers", startResult, maxRows, rdvTiers);
		return new LinkedHashSet<RendezVous>(query.getResultList());
	}

	/**
	 * JPQL Query - findRendezVousByRdvSpecialiteContaining
	 *
	 */
	@Transactional
	public Set<RendezVous> findRendezVousByRdvSpecialiteContaining(String rdvSpecialite) throws DataAccessException {

		return findRendezVousByRdvSpecialiteContaining(rdvSpecialite, -1, -1);
	}

	/**
	 * JPQL Query - findRendezVousByRdvSpecialiteContaining
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<RendezVous> findRendezVousByRdvSpecialiteContaining(String rdvSpecialite, int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findRendezVousByRdvSpecialiteContaining", startResult, maxRows, rdvSpecialite);
		return new LinkedHashSet<RendezVous>(query.getResultList());
	}

	/**
	 * Used to determine whether or not to merge the entity or persist the entity when calling Store
	 * @see store
	 * 
	 *
	 */
	public boolean canBeMerged(RendezVous entity) {
		return true;
	}
}
